<#list "${content.items.controller.packageName}"?split(".") as package>
    <#if !package_has_next>
        <#assign assign_package = package>
    </#if>
</#list>
<#assign tableName = content.content.tableName>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>列表页面</title>
    ${r'${include("/ibp/httl/include/include_css.httl","UTF-8")}'}
    ${r'${include("/ibp/httl/include/include_js.httl","UTF-8")}'}
    <style></style>
</head>
<body>
<cus-template>
    <div layout-fill>
        ${r'${include("//ibp/httl/include/include_menunav.httl","UTF-8")}'}
        <div class="panel-group cus-collapse box-shadow" id="accordion">
            <div class="panel panel-default">
                <!--标题-->
                <div class="panel-heading" role="tab" id="headingOne">
                    <h4 class="panel-title">
                        <a role="button" data-toggle="collapse" data-parent="#accordion"
                           href="#collapseOne" aria-expanded="true"> <i class="fi fi-brush"></i> <span class="text">列表页面</span>
                        </a>
                    </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel">
                    <div class="panel-body">
                        <form class="cus-form" layout="row">
                            <!--查询条件-->
                            <div flex layout="row" flex-xs="100" layout-wrap layout-padding>

                                <div class="form-item" flex="100" flex-gt-sm="50" flex-sm="100">
                                    <label>查询条件</label>
                                    <div flex layout="row">
                                        <input type="text" class="form-control input-sm"  name="" id="">
                                    </div>
                                </div>

                            </div>
                            <!--查询按钮-->
                            <div layout="row" layout-align="center center">
                                <button type="button" class="btn btn-primary btn-sm form-btn"
                                        onclick="queryObjList(1)">
                                    <i class="fa fa-search"></i> 查询
                                </button>
                                &nbsp;
                                <button type="button" class="btn btn-primary btn-sm form-btn"
                                        onclick="resetButton()">
                                    <i class="fi fi-reset"></i> 重置
                                </button>
                            </div>
                            <!-- ********************************隐藏域start**************************************** -->
                            <!--导出时使用-->
                            <input type="hidden" name="exportIds" id="exportIds">
                            <!--导入时使用-->
                            <input type="hidden" name="templateFileName" id="templateFileName">
                            <input type="hidden" name="targetFileName" id="targetFileName">
                            <!-- ********************************隐藏域end**************************************** -->

                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!--表格-->
        <div class="cus-grid" id="grid-wrap">
            <table id="jqGrid"></table>
            <div id="jqGridPager"></div>
        </div>
    </div>

</cus-template>
<script cus-template-script>
    var popLayer;
    $(function () {
        var grid = $("#jqGrid").cusGrid({
            pubToolbars: {
                id: 'grid-wrap',
                align: 'right top',
                actions: [{
                    icon: 'fi fi-add',
                    label: '新建',
                    show: ${r'"${buttonMap_add}"'},//权限按钮是否显示
                    callback: function () {
                        var openurl = ${r'"${appName}'}/${assign_package}/${content.content.tableName}/query${tableName?cap_first}FormView.do?queryFlag=1";
                        //获取选中的行，这是一个数组，多行数组
                        popLayer = top.FloatingLayers.create({
                            background: true,
                            width: '80%',
                            title: {
                                text: '新建',
                                icon: 'fi fi-password-lock'
                            },
                            src: openurl
                        });
                        popLayer.show();
                    }
                }
                ]
            },

            toolbars: {
                actions: [{
                    icon: 'fi fi-edit',
                    label: '修改',
                    show: ${r'"${buttonMap_modify}"'},
                    callback: function () {
                        // 修改校验
                        var id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
                        var status = $("#jqGrid").jqGrid("getRowData", id).status;
                        if (id == '' || id==undefined) {
                            layer.alert("未获取到该列的关键信息无法进行查看或修改！");
                            return;
                        }
                        if (status != '1') {
                            layer.alert("只有草稿状态的才能修改!");
                            return;
                        }
                        <#if content.content.primaryField?? && content.content.primaryField?size gt 0>
                        var openurl =  ${r'"${appName}'}/${assign_package}/${content.content.tableName}/query${tableName?cap_first}FormView.do?queryFlag=2&${content.content.primaryField[0].fieldName}=" + id;
                        <#else>
                        var openurl =  ${r'"${appName}'}/${assign_package}/${content.content.tableName}/query${tableName?cap_first}FormView.do?queryFlag=2&id=" + id;
                        </#if>
                        //获取选中的行，这是一个数组，多行数组
                        popLayer = top.FloatingLayers.create({
                            background: true,
                            width: '80%',
                            title: {
                                text: '修改',
                                icon: 'fi fi-password-lock'
                            },
                            src: openurl
                        });
                        popLayer.show();

                    }
                },{
                    icon: 'fi fi-edit',
                    label: '详情',
                    show: ${r'"${buttonMap_disp}"'},
                    callback: function () {
                        //获取单行选中的行，如果选择了多个，使用此参数将获取选中的最后一行
                        var id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
                        <#if content.content.primaryField?? && content.content.primaryField?size gt 0>
                        var openurl =  ${r'"${appName}'}/${assign_package}/${content.content.tableName}/query${tableName?cap_first}FormView.do?queryFlag=3&${content.content.primaryField[0].fieldName}="+ id;
                        <#else>
                        var openurl =  ${r'"${appName}'}/${assign_package}/${content.content.tableName}/query${tableName?cap_first}FormView.do?queryFlag=3&id="+ id;
                        </#if>
                        popLayer = top.FloatingLayers.create({
                            background: true,
                            width: '80%',
                            title: {
                                text: '详情',
                                icon: 'fi fi-password-lock'
                            },
                            src: openurl
                        });
                        popLayer.show();
                    }
                },{
                    icon: 'fa fa-minus-circle',
                    label: '删除',
                    show: ${r'"${buttonMap_delete}"'},
                    callback: function () {
                        //删除校验
                        var id = $('#jqGrid').jqGrid('getGridParam', 'selrow');
                        var status = $("#jqGrid").jqGrid("getRowData", id).status;
                        if (id == ''||id==undefined) {
                            layer.alert("请选择！");
                            return;
                        }
                        if (status != '1') {
                            layer.alert("只有草稿状态的才能删除!");
                            return;
                        }
                        layer.confirm("您确定要删除吗? 请慎重!",
                            {btn: ['确定', '取消']}, //按钮
                            function (index) {//确定按钮
                                $.ajax({
                                    url: ${r'"${appName}'}/${assign_package}/${content.content.tableName}/delete${tableName?cap_first}.ajax",
                                    <#if content.content.primaryField?? && content.content.primaryField?size gt 0>
                                    data: {${content.content.primaryField[0].fieldName}: id},
                                    <#else>
                                    data: {id: id},
                                    </#if>
                                    dataType: 'json',
                                    type: 'post',
                                    success: function (data) {
                                        if ("1" == data.messageFlag) {
                                            successMsg(data.message);
                                            queryObjList();
                                        } else {
                                            layer.alert(data.message);
                                        }
                                    }
                                }); //end ajax
                                layer.close(index);
                            },
                            function () {
                            }//取消
                        )
                    }
                    }]
            },

            jqGrid: { //jqGrid:http://guriddo.net/  |   http://blog.mn886.net/jqGrid/
                url: ${r'"${appName}'}/${assign_package}/${content.content.tableName}/query${tableName?cap_first}List.ajax",
                postData: $("form").serializeJson(),
                mtype: "POST",
                datatype: "json",
                page: 1,
                colNames: [
                    <#list content.content.fields as item>
                    <#if item.primary == true>
                    '${item.fieldName}'<#if item?has_next>,</#if>
                    <#else>
                    '${item.fieldRemark}'<#if item?has_next>,</#if>
                    </#if>
                    </#list>
                ],
                colModel: [
                    <#list content.content.fields as item>
                    <#if item.primary == true>
                    {name: '${item.fieldName}', key: true, hidden: true}<#if item?has_next>,</#if>
                    <#else>
                    {name: '${item.fieldName}', width: 100, align: 'center',sortable : false}<#if item?has_next>,</#if>
                    </#if>
                    </#list>
                ],
                multiselect: true,//是否显示复选框
                autowidth: true,
                rownumbers: false,
                height: 'auto',
                rowNum: 15,//每页显示多少条
                rowList: [15, 30, 45],
                altRows: true,//斑马线
                viewrecords: true,//显示右侧数据信息
                pager: '#jqGridPager',
                showBatchDelete: false

            }
        });

    });


    //查询按钮
    function queryObjList(flag) {
        $("#exportIds").val('');
        $("#jqGrid").jqGrid('setGridParam', {
            postData: $("form").serializeJson()
        }).trigger('reloadGrid');//重新载入
    }


</script>
</body>
</html>